/**
 * File Comment: Ita a GUI
 */
package edu.gatech.oad.project.presentation;
//$codepro.audit.disable
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

import edu.gatech.oad.project.operations.data.Appointment;

/**
 * This class is a panel that allows the user
 * to interact with the GUI to view a list of
 * a patient's treatment records.
 * 
 * @author Group 17
 * @version 1
 */
public class NursePatientListTR extends JPanel {
  
  /**
   * Field driver: holds the Driver connected to the GUI
   */
  private Driver driver;
  
  /**
   * Field patient: name of the patient
   */
  public String patient;
  
  /**
   * Field list: list of patient's treatment records
   */
  public JList list;
  
  /**
   * Field btnEdit: edit treatment record button
   */
  public JButton btnEdit;
  
  /**
   * Field btnBackToPatient: back button
   */
  public JButton btnBackToPatient;

 /**
  * Constructor.
  * 
  * @param driver the Driver connected to the GUI
  * @param patient the name of the patient
  */
 public NursePatientListTR(Driver driver,String patient) {
   this.driver = driver;
   this.patient = patient;
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[]{0, 0, 0};
  gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);
  
  JLabel lblTreatmentRecords = new JLabel("Treatment Records");
  lblTreatmentRecords.setFont(new Font("Lucida Grande", Font.PLAIN, 30));
  GridBagConstraints gbc_lblTreatmentRecords = new GridBagConstraints();
  gbc_lblTreatmentRecords.gridwidth = 5;
  gbc_lblTreatmentRecords.insets = new Insets(0, 0, 5, 0);
  gbc_lblTreatmentRecords.gridx = 0;
  gbc_lblTreatmentRecords.gridy = 0;
  add(lblTreatmentRecords, gbc_lblTreatmentRecords);
  
  JLabel lblPastAppointments = new JLabel("Past Appointments");
  GridBagConstraints gbc_lblPastAppointments = new GridBagConstraints();
  gbc_lblPastAppointments.insets = new Insets(0, 0, 5, 5);
  gbc_lblPastAppointments.gridx = 0;
  gbc_lblPastAppointments.gridy = 2;
  add(lblPastAppointments, gbc_lblPastAppointments);
  
  list = new JList();
  GridBagConstraints gbc_list = new GridBagConstraints();
  gbc_list.gridheight = 4;
  gbc_list.gridwidth = 2;
  gbc_list.insets = new Insets(0, 0, 5, 5);
  gbc_list.fill = GridBagConstraints.BOTH;
  gbc_list.gridx = 1;
  gbc_list.gridy = 2;
  add(list, gbc_list);
  
  btnEdit = new JButton("Edit");
  btnEdit.addActionListener(new ButtonListener1(this));
  GridBagConstraints gbc_btnEdit = new GridBagConstraints();
  gbc_btnEdit.insets = new Insets(0, 0, 5, 5);
  gbc_btnEdit.gridx = 1;
  gbc_btnEdit.gridy = 6;
  add(btnEdit, gbc_btnEdit);
  
  btnBackToPatient = new JButton("Back to Patient Info");
  btnBackToPatient.addActionListener(new ButtonListener2(this));
  GridBagConstraints gbc_btnBackToPatient = new GridBagConstraints();
  gbc_btnBackToPatient.insets = new Insets(0, 0, 5, 5);
  gbc_btnBackToPatient.gridx = 2;
  gbc_btnBackToPatient.gridy = 6;
  add(btnBackToPatient, gbc_btnBackToPatient);
 } // end constuctor method
 
 /**
  * Get the Driver.
  * 
  * @return the Driver connected to the GUI
  */
 public Driver getDriver()
 {
   return this.driver;
 } // end getDriver method
 
 /**
  * Get the selected appointment.
  * 
  * @return the selected Appointment
  */
 public Appointment getSelected()
 {
   String app = (String)this.list.getSelectedValue();
   //write code to get Appointment object from database;
   return null; //need to change
 } // end getSelected method

 /**
  * This private inner class implements ActionListener for btnEdit.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener1 implements ActionListener
 {
   /**
    * Field trl: the NursePatientListTR being used
    */
   private NursePatientListTR trl;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param trl the NursePatientListTR being used
    */
   private ButtonListener1(NursePatientListTR trl)
   {
     this.trl = trl;
     this.driver = trl.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new NursePatientTR(this.driver,this.trl.getSelected()));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener1 class
 
 /**
  * This private inner class implements ActionListener for btnBackToPatient.
  * 
  * @author Group 17
  * @version 1
  */
  private class ButtonListener2 implements ActionListener
 {
    /**
     * Field trl: the NursePatientListTR being used
     */
   private NursePatientListTR trl;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param trl the NursePatientListTR being used
    */
   private ButtonListener2(NursePatientListTR trl)
   {
     this.trl = trl;
     this.driver = trl.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new NursePatientInfo(this.driver,this.trl.patient));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener2 class
} // end NursePatientListTR class